home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / compact.doc < prev    next >
Text File  |  1995-03-31  |  5KB  |  134 lines

  1. (Comp.sys.handhelds) 
  2. Item: 1997 by seroussi at hplabsb.HP.COM 
  3. Author: [Gadiel Seroussi] 
  4.   Subj: HP48 compact arrays 
  5.   Date: Fri Feb 08 1991 
  6.  
  7. The COMPACT directory uses HP48 linked arrays to implement "compact arrays" 
  8. of positive integers.  These arrays allow you to store large tables of 
  9. positive binary integers using significantly less storage than would be 
  10. required with either real arrays or lists of binaries, with an access time 
  11. comparable to that of real arrays (much faster than lists of binaries). 
  12.  
  13. A compact array shows on the stack as "Linked Array", and cannot be edited 
  14. directly (conversion routines are provided). 
  15.  
  16. The internal structure of a compact array is as follows: 
  17.  
  18. <02a0a> - header (5 nib) 
  19. <size>  - size of object excluding header (5 nib) 
  20. <isize> - size of array elements, in nibbles (5 nib) 
  21. <n>     - number of elements (5 nib) 
  22. <element 1> <element 2> ..... <element n>  (<isize> nibbles each). 
  23.  
  24. Other headers could have been chosen but "linked array" was unused enough 
  25. to justify the choice (and choices like "code" or "string" would be 
  26. confusing). 
  27.  
  28. The following variables are included: 
  29.  
  30. IGETB: retrieve an element of the array, as a binary number. 
  31.  
  32.         2: A (compact array) 
  33.         1: k (Real)          ----> 1: A(k)  (binary) 
  34.  
  35. IGET: retrieve an element of the array, as a real number. 
  36.  
  37.         2: A (compact array) 
  38.         1: k (Real)          ----> 1: A(k)  (Real). 
  39.  
  40.         If k <= 0, the number of elements of the array is returned. 
  41.         Subscript range is checked. 
  42.  
  43. IPUT: store a value in the array. 
  44.  
  45.         3: A (compact array) 
  46.         2: k (Real) 
  47.         1: x (Real or binary)  ----> 1: A (compact array, with A(k)=x). 
  48.  
  49.         Subscript range is checked, k <= 0 is not allowed. The value x is 
  50.         truncated to the size of the array elements. 
  51.  
  52. ICON: generate a compact array with constant elements. 
  53.  
  54.         3: n (Real) 
  55.         2: isize (Real) 
  56.         1: c (Real or binary)  ----> 1: A (compact array). 
  57.  
  58.         A has n elements, isize nibbles each, all set to the value c. While 
  59.         it is legal to set isize > 16, the access routines will only handle 
  60.         up to 16 nibble values. 
  61.  
  62. ISIZE: find out the value of <isize>. 
  63.  
  64.         1: A (compact array)   ----> 1: isize (Real) 
  65.  
  66. ITOA: Convert compact array to real array. 
  67.  
  68.         1: A (compact array)   ----> 1: RA (Array of Real). 
  69.  
  70. ITOB: Convert compact array to list of binaries. 
  71.  
  72.         1: A (compact array)   ----> 1: BL (List of Binary). 
  73.  
  74. ATOI: Convert real array to compact array. 
  75.  
  76.         2: RA (Array of Real) 
  77.         1: isize (real)        ----> 1: A (compact array) 
  78.  
  79. BTOI: Convert list of binaries to compact array. 
  80.  
  81.         2: BL (List of Binary) 
  82.         1: isize (real)        ----> 1: A (compact array) 
  83.  
  84.         For both ATOI and BTOI, if isize == 0, the least number of nibbles 
  85.         will be used that can accommodate the largest value in RA or BL 
  86.         (resp.). 
  87.  
  88. BMAX: Find the largest value in a list of binaries (aux. function). 
  89.  
  90. p.small: an example of a compact array. A list of the first 1000 prime 
  91. numbers. It takes 2010 bytes of storage, compared to 8012.5 bytes for a 
  92. real array, or around 7000 bytes for a "well packed" list of binaries 
  93. (which ITOB will NOT produce). 
  94.  
  95. Other remarks: 
  96. 1. The conversion routines are written in user language. Since I consider 
  97.    them "one-time" events, no special effort was made to make them faster. 
  98. 2. All access routines are affected by the current setting of the binary 
  99.    word size (set word size >= isize for things to work properly). 
  100.  
  101. This package was developed for a Version D ROM. It may or may not work on 
  102. yours. It may or may not destroy your data and/or your calculator. Use it 
  103. at your own risk. No warranties of any kind. 
  104.  
  105. Enjoy, 
  106.  
  107. Gadiel Seroussi 
  108. HP Labs (but no relation to Corvallis) 
  109.  
  110. ---------- 
  111.   Resp: 1 of 1 by jurjen at cwi.nl 
  112. Author: [Jurjen NE Bos] 
  113.   Date: Fri Feb 08 1991 19:15 
  114.  
  115. This program (for storing arrays of integers in a compact form) uses linked 
  116. arrays as the data type of choice.  The author says: 
  117.  
  118.         Other headers could have been chosen but "linked array" was 
  119.         unused > enough to justify the choice (and choices like 
  120.         "code" or "string" would > be confusing). 
  121.  
  122. How do we know for sure that the HP48 ROM does not make any assumptions 
  123. about the contents of a Linked Array?  The name suggests that the contents 
  124. may have a structure that contains addresses of other objects. 
  125.  
  126. Are you sure the garbage collector allows one to make Linked Array with 
  127. anything in it? 
  128.  
  129. For that matter, does anybody know what a Linked Array actually does?  I 
  130. know there is one in the ROM (sorry, I don't know the address), but it 
  131. wasn't clear to me what it did.  It did contain machine code, I recall. 
  132. Until we understand them, I don't consider it a safe idea to use Linked 
  133. Arrays as objects in a program. 
  134.